import { RequestParameterSerializeInterceptor } from '../request-parameter-serialize/request-parameter-serialize.interceptor'
import { ResponseParameterSerializeInterceptor } from '../response-parameter-serialize/response-parameter-serialize.interceptor'

/**
 * 忽略序列化
 * @param option
 * @returns
 */
export function IgnoreParameterSerialize(option: IgnoreParameterSerializeOption): MethodDecorator {
  return (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => {
    const context = target.constructor

    if (option.request) {
      if (!RequestParameterSerializeInterceptor.IGNORES.has(context)) {
        RequestParameterSerializeInterceptor.IGNORES.set(context, [propertyKey])
      } else {
        RequestParameterSerializeInterceptor.IGNORES.get(context).push(propertyKey)
      }
    }

    if (option.response) {
      if (!ResponseParameterSerializeInterceptor.IGNORES.has(context)) {
        ResponseParameterSerializeInterceptor.IGNORES.set(context, [propertyKey])
      } else {
        ResponseParameterSerializeInterceptor.IGNORES.get(context).push(propertyKey)
      }
    }
  }
}

export interface IgnoreParameterSerializeOption {
  request?: boolean
  response?: boolean
}
